//
//  ZhuantiViewController.m
//  Travel
//
//  Created by lanou3g on 15/4/11.
//  Copyright (c) 2015年 &#21556;&#21697;&#27901;. All rights reserved.
//

#import "ZhuantiViewController.h"
#import <AFNetworking.h>
#import "Special.h"
#import "SpeacialTableViewCell.h"
#import "ZuantiDetailViewController.h"
@interface ZhuantiViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,retain)UITableView *tableView2;
@property (nonatomic,retain)NSMutableArray *arr2;
@end

@implementation ZhuantiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createTableView1AndTableView2];
    [self requestForTableView2];
}
- (void)createTableView1AndTableView2
{
    self.title = [NSString stringWithFormat:@"%@口袋书",self.numberNameZhuanti];
    self.tableView2 = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView2.delegate = self;
    self.tableView2.dataSource = self;
    self.tableView2.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView2];
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // self.traveCell = (TravelCell *)[tableView cellForRowAtIndexPath:indexPath];
    
    
    return 160;
    
}

- (void)requestForTableView2
{
    self.arr2 = [NSMutableArray array];
    NSString *string = [NSString stringWithFormat:@"https://chanyouji.com/api/articles.json?destination_id=%@&page=1",self.numberStr];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  //  NSMutableArray *array = [NSMutableArray array];
    [manager GET:string parameters:self success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSArray *arrayA = responseObject;
        for (NSMutableDictionary *dic in arrayA) {
            Special *note = [[Special alloc]init];
            [note setValuesForKeysWithDictionary:dic];
            [self.arr2 addObject:note];
        }
        
       
        
        
        // NSLog(@"%ld",self.arr2.count);
        [self.tableView2 reloadData];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        //???网络出现错误时候可以给提示
        
        
    }];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    Special *spe = [self.arr2 objectAtIndex:indexPath.row];
    ZuantiDetailViewController *zuan = [[ZuantiDetailViewController alloc]init];
    NSString *str = [NSString stringWithFormat:@"%@",spe.ID];
    
    zuan.urlStr = str;
    
    [self.navigationController pushViewController:zuan animated:YES];

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr2.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str2 = @"heheh";
    SpeacialTableViewCell *cell = [self.tableView2 dequeueReusableCellWithIdentifier:str2];
    if (cell == nil) {
        cell = [[SpeacialTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str2];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    Special *spe = [self.arr2 objectAtIndex:indexPath.row];
    cell.spe = spe;
    // Travelnote *notes = [self.arr1 objectAtIndex:indexPath.row];
    // cell.notes = notes;
    
    return cell;

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
